//
//  AddressCollectionViewCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "AddressCollectionViewCell.h"
#import "AddressModel.h"

@interface AddressCollectionViewCell ()
//名字
@property (nonatomic, strong) UILabel * nameLab;
//
@property (nonatomic, strong) UILabel * nameLab1;
@property (nonatomic, strong) UIImageView * iconView;
@end

@implementation AddressCollectionViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    self.contentView.backgroundColor = kRandomColor;
//    self.contentView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:self.nameLab1];
    [self addSubview:self.nameLab];
    [self addSubview:self.iconView];
}

- (void)layoutInit {
    weakself(ws);
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView.mas_left).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView.mas_right).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.height.mas_equalTo(20);
    }];

    [self.nameLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView.mas_left).offset(kMargin10);
        make.right.mas_equalTo(ws.iconView.mas_left).offset(-kMargin10);
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView.mas_bottom).offset(-kMargin10);
    }];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(ws.contentView.mas_right).offset(-kMargin10);
        make.centerY.mas_equalTo(ws.nameLab1);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
}
#pragma mark setter getter
- (void)setAddressModel:(AddressModel *)addressModel {
    _addressModel = addressModel;
    _nameLab.text = [NSString stringWithFormat:@"%@", addressModel.name? addressModel.name : @""];
    
//    name address1English
//    address2English  cityTownEnglish
//    address1Chinese address2Chinese
//    cityTownChinese zipPostalEnglish
    _nameLab1.text = [NSString stringWithFormat:@"%@,%@ \n%@ \n%@ \n%@ \n%@ \n%@\n",
                      addressModel.address1English ? addressModel.address1English : @"",
                      addressModel.address2English ? addressModel.address2English : @"",
                      addressModel.cityTownEnglish ? addressModel.cityTownEnglish : @"",
                      addressModel.address1Chinese ? addressModel.address1Chinese : @"",
                      addressModel.address2Chinese ? addressModel.address2Chinese : @"",
                      addressModel.cityTownChinese ? addressModel.cityTownChinese : @"",
                      addressModel.zipPostalChinese ? addressModel.zipPostalChinese : @""];

    _iconView.hidden = !addressModel.isShowArrow;
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLab.backgroundColor = kRandomColor;
        _nameLab.numberOfLines = 1;
    }
    return _nameLab;
}


- (UILabel *)nameLab1 {
    if (!_nameLab1) {
        self.nameLab1 = [UILabel new];
        _nameLab1.textAlignment = NSTextAlignmentLeft;
        _nameLab1.font = kGeneralFontSize;
        _nameLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLab1.numberOfLines = 0;
        _nameLab1.backgroundColor = kRandomColor;
    }
    return _nameLab1;
}
- (UIImageView *)iconView {
    if (!_iconView) {
        self.iconView = [UIImageView new];
        _iconView.image = [UIImage imageNamed:@"return-拷贝"];
        _iconView.hidden = YES;
    }
    return _iconView;
}

@end
